package com.horse.cloud.data.access;

import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;


@Configuration
public class MapperConfig implements EnvironmentAware {


    private String basePackage;

    @Bean
    public MapperScannerConfigurer mapperScannerConfigurer() {
        MapperScannerConfigurer configure = new MapperScannerConfigurer();
        configure.setBasePackage(basePackage);
        configure.setMarkerInterface(BaseMapper.class);
        return configure;
    }

    @Override
    public void setEnvironment(Environment environment) {

        Binder binder = Binder.get(environment);
        this.basePackage = binder.bind("horse.mybatis.mapper-base-package", String.class).get();
    }
}